package test;

/**
 * Created with IntelliJ IDEA.
 * Description:二刷排序
 * User: 东莞呵呵
 * Date:2022-07-24
 * Time:16:49
 */
public class InsertSort implements ISort{
    public void sort(int[] array){
        System.out.println("插入排序：");
        for (int i = 1; i < array.length; i++) {
            int tmp=array[i];
            int j = i-1;
            //不能忽略j=0的情况
            for ( ;j >= 0; j--) {
                if(tmp<array[j]){
                    array[j+1]=array[j];
                }else{
                    break;
                }
            }
            array[j+1]=tmp;
        }
    }
}
